package org.gikolet.ch2.data;

import java.io.Serializable;
import java.util.Date;

public class ThreadHeader implements Serializable {

	/**
	 * シリアルバージョンID。
	 */
	private static final long serialVersionUID = 116114519127857855L;

	private Long id;

	private Board board;

	private String threadKey;

	private String subject;

	private Integer resCount;

	private Date date;

	private Date lastModified;

	private Long byteSize;

	public ThreadHeader(ThreadHeader subject) {
		this(subject.id, subject.board, subject.threadKey, subject.subject,
				subject.resCount, subject.date, subject.lastModified,
				subject.byteSize);
	}

	public ThreadHeader(Board board, String threadKey) {
		this(null, board, threadKey, null, null, null, null, null);
	}

	public ThreadHeader(Long id, Board board, String threadKey, String subject,
			Integer resCount, Date date, Date lastModified, Long byteSize) {
		this.id = id;
		this.board = board;
		this.threadKey = threadKey;
		this.subject = subject;
		this.resCount = resCount;
		this.date = date;
		this.lastModified = lastModified;
		this.byteSize = byteSize;
	}

	public void setThreadHeader(ThreadHeader threadHeader) {
		this.id = threadHeader.id;
		this.board = new Board(threadHeader.board);
		this.threadKey = threadHeader.threadKey;
		this.subject = threadHeader.subject;
		this.resCount = threadHeader.resCount;
		this.date = threadHeader.date;
		this.lastModified = threadHeader.lastModified;
		this.byteSize = threadHeader.byteSize;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Board getBoard() {
		return this.board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	public String getThreadKey() {
		return this.threadKey;
	}

	public void setThreadKey(String threadKey) {
		this.threadKey = threadKey;
	}

	public String getSubject() {
		return this.subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public Integer getResCount() {
		return this.resCount;
	}

	public void setResCount(Integer resCount) {
		this.resCount = resCount;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getLastModified() {
		return this.lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	public Long getByteSize() {
		return this.byteSize;
	}

	public void setByteSize(Long byteSize) {
		this.byteSize = byteSize;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ThreadHeader) {
			return equals((ThreadHeader) obj);
		}
		return false;
	}

	public boolean equals(ThreadHeader subject) {
		if (subject != null && equalsBoard(subject.board)
				&& equalsThreadKey(subject.threadKey)) {

			return true;
		}
		return false;
	}

	private boolean equalsBoard(Board board) {
		if (this.board == board) {
			return true;

		} else if (this.board != null && this.board.equals(board)) {
			return true;
		}
		return false;
	}

	private boolean equalsThreadKey(String threadKey) {
		if (this.threadKey == threadKey) {
			return true;

		} else if (this.threadKey != null && this.threadKey.equals(threadKey)) {
			return true;
		}
		return false;
	}
}
